﻿using EmoneyWeiXinEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using EmoneyWeiXinCommon;
using System.Data;

namespace EmoneyWeiXinDAL
{
    public class MaterialDAL
    {
        public static int Insert(MaterialEntity entity)
        {
            string sql = "INSERT INTO Material VALUES(@Ma_Name,@weixinId,@Ma_Type,@Media_id,@ImgUrl,@Ma_Type2,@RemaindTime,GETDATE())";
            SqlParameter[] paras = 
            {
              new SqlParameter("@Ma_Name",entity.Ma_Name),
              new SqlParameter("@weixinId",entity.weixinId),
              new SqlParameter("@Ma_Type",entity.Ma_Type),
              new SqlParameter("@Media_id",entity.Media_id),
              new SqlParameter("@ImgUrl",entity.ImgUrl),
              new SqlParameter("@Ma_Type2",entity.Ma_Type2),
              new SqlParameter("@RemaindTime",entity.RemaindTime)
            };
            return SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, System.Data.CommandType.Text, sql, paras);

        }


        public static List<MaterialEntity> GetListByPage(int pageSize, int pageIndex, string whereText, string orderBy, out int totalPage)
        {
            PageHelper pgHelper = new PageHelper("Material", "ID");
            pgHelper.CurrentPage = pageIndex;
            pgHelper.PageSize = pageSize;
            pgHelper.WhereText = whereText;
            pgHelper.Orderby = orderBy;
            DataTable dt = pgHelper.GetData();
            totalPage = pgHelper.TotalRecord;
            return SQLHelper.DataConvert<MaterialEntity>(dt);
        }
    }
}
